Imports Ocean.OceanFramework.Validation.StringValidationRules

Namespace Validation

    Public Class RegulatExpressionRuleEventArgs
        Inherits RuleEventArgs

#Region " Declarations "

        Private _enumRegularExpressionPatternType As RegularExpressionPatternType = RegularExpressionPatternType.Custom
        Private _enumRequiredEntry As RequiredEntry = RequiredEntry.No
        Private _strCustomRegularExpressionPattern As String = String.Empty

#End Region

#Region " Properties "

        Public Property CustomRegularExpressionPattern() As String
            Get
                Return _strCustomRegularExpressionPattern
            End Get
            Set(ByVal Value As String)

                If Value = String.Empty Then
                    _strCustomRegularExpressionPattern = String.Empty
                    Exit Property
                End If

                If Me.RegularExpressionPatternType <> Validation.RegularExpressionPatternType.Custom Then
                    Throw New ArgumentException("Before setting a custom pattern, the Pattern Type must be custom.")
                End If

                If Not IsRegularExpressionPatternValid(Value) Then
                    Throw New ArgumentOutOfRangeException("Value", "Invalid CustomRegularExpressionPattern")
                End If

                _strCustomRegularExpressionPattern = Value
            End Set
        End Property

        Public Property RegularExpressionPatternType() As RegularExpressionPatternType
            Get
                Return _enumRegularExpressionPatternType
            End Get
            Set(ByVal Value As RegularExpressionPatternType)
                _enumRegularExpressionPatternType = Value
            End Set
        End Property

        Public Property RequiredEntry() As RequiredEntry
            Get
                Return _enumRequiredEntry
            End Get
            Set(ByVal Value As RequiredEntry)
                _enumRequiredEntry = Value
            End Set
        End Property

#End Region

#Region " Constructor "

        Public Sub New(ByVal enumRegularExpressionPatternType As RegularExpressionPatternType, ByVal enumRequiredEntry As RequiredEntry, ByVal strCustomMessage As String, ByVal strPropertyFriendlyName As String, ByVal strPropertyName As String, ByVal strRuleSet As String)
            MyBase.New(strCustomMessage, strPropertyFriendlyName, strPropertyName, strRuleSet)

            If enumRegularExpressionPatternType = Validation.RegularExpressionPatternType.Custom Then
                Throw New InvalidOperationException("This constructor does not support assigning the RegularExpressionPatternType to Custom.  Use other constructor.")
            End If

            _enumRegularExpressionPatternType = enumRegularExpressionPatternType
            _enumRequiredEntry = enumRequiredEntry
        End Sub

        Public Sub New(ByVal e As RegularExpressionValidatorAttribute, ByVal strPropertyName As String)
            MyBase.New(strPropertyName, e.PropertyFriendlyName, e.RuleSet, e.CustomMessage)
            _enumRegularExpressionPatternType = e.RegularExpressionPatternType

            If e.RegularExpressionPatternType = RegularExpressionPatternType.Custom Then

                If Not IsRegularExpressionPatternValid(e.CustomRegularExpressionPattern) Then
                    Throw New ArgumentOutOfRangeException("CustomRegularExpressionPattern", "Invalid CustomRegularExpressionPattern")
                End If

                _strCustomRegularExpressionPattern = e.CustomRegularExpressionPattern
            End If

            _enumRequiredEntry = e.RequiredEntry
        End Sub

        Public Sub New(ByVal strCustomRegularExpressionPattern As String, ByVal enumRequiredEntry As RequiredEntry, ByVal strCustomMessage As String, ByVal strPropertyFriendlyName As String, ByVal strPropertyName As String, ByVal strRuleSet As String)
            MyBase.New(strCustomMessage, strPropertyFriendlyName, strPropertyName, strRuleSet)
            _enumRegularExpressionPatternType = Validation.RegularExpressionPatternType.Custom
            _enumRequiredEntry = enumRequiredEntry

            If Not IsRegularExpressionPatternValid(strCustomRegularExpressionPattern) Then
                Throw New ArgumentOutOfRangeException("strCustomRegularExpressionPattern", "Invalid CustomRegularExpressionPattern")
            End If

            _strCustomRegularExpressionPattern = strCustomRegularExpressionPattern
        End Sub

#End Region

    End Class

End Namespace
